﻿using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.Reporting.BusinessLogic
{
    public static class EnumerableExtensions
    {
        public static IEnumerable<List<T>> Batch<T>(this IEnumerable<T> items, int count)
        {
            if (items == null) return null;

            return items.Select((item, index) => new { item, index })
                        .GroupBy(x => x.index / count)
                        .Select(g => g.Select(x => x.item).ToList().ToList());
        }
    }
}
